﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Service;
using PersonalHealth.Data.Model;
using PersonalHealth.Data.Data;
using PersonalHealth.Data.IService;
using System.Data.Entity;
using Core.UnitOfWork;
using PersonalHealth.Data.Repository;
using System.Transactions;

namespace PersonalHealth.Data.Service
{
    public class OfficalDataThresholdService : Service<OfficalDataThreshold, HealthContext>, IOfficalDataThresholdService
    {

        public Dictionary<string, OfficalDataThreshold> GetAllDict()
        {
            using (HealthContext context = new HealthContext())
            {
                IUnitOfWork unitOfWork = new UnitOfWork(context);

                IOfficalDataThresholdRepository rep = new OfficalDataThresholdRepository(unitOfWork);

                var list = (from type in context.MeasureSubTypes
                            join data in context.OfficalDataThresholds on type.Id equals data.MeasureSubTypeId
                            where 1 == 1
                            select new { type = type, data = data }
                                ).ToList();

                Dictionary<string, OfficalDataThreshold> dict = new Dictionary<string, OfficalDataThreshold>();
                foreach (var i in list)
                {
                    dict.Add(i.type.Code, i.data);
                }
                return dict;
            }
        }

    }
}
